#!/bin/bash

# Modified for EchoIRLP update
# EchoIRLPinstall 11/04/03 - wa6rqd
# fixed ECHO_NODE_DESC 11/24/03 - wa6rqd
# removed exit error at echoIRLP unpack 11/25/03 - wa6rqd
# changed ECHO_MY_CALL to ECHO_NODE_CALL in environment build 11/26/03 - wa6rqd
#
# v1.0: 12-Jan-04 VK2XJG: Complete Redesign for new EchoIRLP file structure. Added multiple new sections
# v1.1: 17-Feb-04 VK2XJG: Corrected wc support for RH6.2
# v1.2: 06-Mar-04 VK2XJG: Corrected custom_decode, added check for gcc/make, added fixes for status updates
# v1.3: 04-Apr-04 VK2XJG: Corrected compiler check, added sanity check for # and * in ECHO_PRE input section
# v1.4: 21-May-04 VK3JED: Used variables for thebridge and tbdcnv
#
#
#
#
################################################################################
#
# MUST BE RAN AS REPEATER
if [ `/usr/bin/whoami` != "repeater" ] ; then
  echo "This program must be run as user REPEATER!"
  exit 1
fi

#Sets the IP of the download server
SERVERIP=redhat.irlp.net
ENVFILE=$ID/custom/echo_environment
IRLP=/home/irlp
SCRIPTUPDATE=$IRLP/noupdate/scripts

#Sets the install directory (/home/irlp required)
ID=/home/EchoIRLP
CUSTOM=$ID/custom
SRC=/usr/src
TBD=thebridge-0.76.tgz
TBDCNV=tbdcnv-0.03.tar

clear
echo "This script will update the IRLP sfswrapper file"
echo "  "
echo -n  "Press ENTER to continue or CTRL-C to cancel : " ; read
clear



echo -n Checking for noupdate directory...
if [ ! -f $IRLP/noupdate ]; then
  echo  "Directory does not exist, nothing to do!"
  exit 0
  mkdir $IRLP/noupdate
  mkdir $SCRIPTUPDATE
elif [ ! -f $SCRIPT ]; then
  echo -n "Directory does not exist, nothing to do!"
  exit 0
  mkdir $SCRIPTUPDATE
fi
echo done!

cd $SCRIPTUPDATE

if [ -f $SCRIPTUPDATE/sfswrapper ]; then
  echo "Custom sfswrapper found in $SCRIPTUPDATE, removing..."
  mv $SCRIPTUPDATE/sfswrapper $CUSTOM/sfswrapper-backup
  echo "Existing sfswrapper has been moved to $CUSTOM/sfswrapper-backup"
  $SCRIPT/update files
  exit 0
fi

echo Downloading updates...

/usr/bin/ncftpget -u echoinstall -p ech01rlp $SERVERIP $SCRIPTUPDATE sfswrapper
chmod 755 $SCRIPTUPDATE/sfswrapper

if [ "$NOUPDATE" != "YES" ]; then
  echo "Please ensure you set NOUPDATE=YES in your IRLP environment"
  echo "and restart IRLP by running /home/irlp/custom/rc.irlp as root."
else
  $SCRIPT/update files
fi

echo "Update complete!"
